﻿using System.Drawing;
using GIMS.Def.Arguments;
using GIMS.Def.Operators;
using GIMS.Def.Settings;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GIMS.Def.Test
{
    /// <summary>
    ///This is a test class for DrawOperatorTest and is intended
    ///to contain all DrawOperatorTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DrawOperatorTest
    {
        /// <summary>
        /// Reset GlobalSettings
        /// </summary>
        [TestInitialize()]
        public void MyTestInitialize()
        {
            GlobalSettings_Accessor.instance = null;
        }

        /// <summary>
        ///A test for CreateScriptPart - Draw operator (rectangle) with "fill Setting"
        ///</summary>
        [TestMethod()]
        public void CreateScriptPartTest1()
        {
            DrawOperator_Accessor target = new DrawOperator_Accessor();
            DrawArgument arg = (DrawArgument)target.Argument;
            arg.Shape = Shape.rectangle;
            arg.P0 = new Point(10, 20);
            arg.P1 = new Point(30, 40);
            setFillSetting(target);
            Assert.AreEqual("-fill rgba(255,20,147,1) -draw \"rectangle 10,20 30,40\"", target.CreateScriptPart());
        }

        /// <summary>
        ///A test for CreateScriptPart - Draw operator (circle) with "stroke Setting
        ///</summary>
        [TestMethod()]
        public void CreateScriptPartTest2()
        {
            DrawOperator_Accessor target = new DrawOperator_Accessor();
            DrawArgument arg = (DrawArgument)target.Argument;
            arg.Shape = Shape.circle;

            //the GUI access/modify the points this way
            arg.P0X = 11;
            arg.P0Y = 22;
            arg.P1X = 33;
            arg.P1Y = 44;

            setStrokeSetting(target);

            string command = target.CreateScriptPart();
            Assert.AreEqual("-stroke rgba(255,20,147,1) -draw \"circle 11,22 33,44\"", command);
        }

        /// <summary>
        ///A test for CreateScriptPart - Draw operator (text) with "stroke Setting and "strokeWidth Setting"
        ///</summary>
        [TestMethod()]
        public void CreateScriptPartTest3()
        {
            DrawOperator_Accessor target = new DrawOperator_Accessor();
            DrawArgument arg = (DrawArgument)target.Argument;
            arg.Shape = Shape.text;
            arg.P0 = new Point(10, 20);
            arg.Text = "hello world";

            setStrokeSetting(target);
            setStrokeWidthSetting(target);

            string command = target.CreateScriptPart();
            Assert.AreEqual("-stroke rgba(255,20,147,1) -strokewidth 12 -draw \"text 10,20 'hello world'\"", command);
        }

        private void setFillSetting(DrawOperator_Accessor target)
        {
            target.fillSetting.Active = true;
            ColorArgument arg1 = (ColorArgument)target.fillSetting.Argument;
            arg1.Color = Color.DeepPink; 
        }

        private void setStrokeSetting(DrawOperator_Accessor target)
        {
            target.strokeSetting.Active = true;
            ColorArgument arg1 = (ColorArgument)target.strokeSetting.Argument;
            arg1.Color = Color.DeepPink;
        }

        private void setStrokeWidthSetting(DrawOperator_Accessor target)
        {
            target.strokeWidthSetting.Active = true;
            NumberArgument arg = (NumberArgument) target.strokeWidthSetting.Argument;
            arg.Value = 12;
        }
    }
}
